from PyQt5.QtCore import Qt, QModelIndex
from PyQt5.QtWidgets import QStyledItemDelegate, QTextEdit


class Calculation(QStyledItemDelegate):
    def __init__(self, parent, constraints):
        super().__init__(parent)
        self.constraints = constraints


    def createEditor(self, parent, option, index):
        textarea = QTextEdit(parent)
        return textarea

        
    def setEditorData(self, textarea, index):
        textarea.setText(index.model().data(index, Qt.EditRole))


    def setModelData(self, textarea, model, index):
        model.setData(index, textarea.toPlainText(), Qt.EditRole)


    def updateEditorGeometry(self, textarea, option, index):
        textarea.setGeometry(option.rect)
